package com.mor.common.globalPathSetting;

/**
 * Created by dell on 2018/3/14.
 */

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created on   2018年6月22日
 * Description: [设定静态资源URL]
 * Copyright:   Copyright (c) 2018
 * Department:  研发部
 * @author:     wz
 * @version:    1.0
 */
public class StaticPathContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        Properties p = new Properties();
        String file = "conf/config.properties";
        try {
            InputStream in = this.getClass().getClassLoader().getResourceAsStream(file);
            //sce.getServletContext().getResourceAsStream("/WEB-INF/classes/conf/config.properties");
            p.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        sce.getServletContext().setAttribute("staticPath", p.getProperty("static.resource.url", ""));
    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }
}